package demoMod.nanaki.cards.nanaki;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.actions.common.PutOnDeckAction;
import com.megacrit.cardcrawl.actions.utility.UseCardAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.utils.GetWaitAction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RepeatHymn extends AbstractNanakiCard {
    public static final String ID = NanakiMod.makeID("RepeatHymn");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/RepeatHymn";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.COMMON;
    private static final CardTarget TARGET = CardTarget.SELF;

    private static final int COST = 0;

    public RepeatHymn() {
        super(ID, NAME, NanakiMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.baseBlock = 4;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> upgradeBlock(2);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(GetWaitAction.doAndWait(() -> {
            if (!AbstractDungeon.actionManager.actions.isEmpty()) {
                List<AbstractGameAction> tmp = new ArrayList<>(AbstractDungeon.actionManager.actions);
                Collections.reverse(tmp);
                for (AbstractGameAction action : tmp) {
                    if (action instanceof UseCardAction) {
                        ((UseCardAction) action).reboundCard = true;
                        break;
                    }
                }
            }
        }, 0.0F));
        addToBot(new GainBlockAction(p, p, this.block));
    }
}
